package com.hospital.demo.service.impl.jiajinpeng;

import com.hospital.demo.mapper.jiajinpeng.AdHospitalMapper;
import com.hospital.demo.mapper.jiajinpeng.PatientMapper;
import com.hospital.demo.mapper.jiajinpeng.polyMapper.AddAllHospitalMapper;
import com.hospital.demo.model.jiajinpeng.AdHospital;
import com.hospital.demo.model.jiajinpeng.Patient;
import com.hospital.demo.model.jiajinpeng.poly.AddAllHospital;
import com.hospital.demo.service.jiajinpeng.AdHospitalSer;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class AdHospitalImpl implements AdHospitalSer {

    @Autowired
    private AddAllHospitalMapper addAllHospitalMapper;

    @Autowired
    private AdHospitalMapper adHospitalMapper;

    @Autowired
    private PatientMapper patientMapper;

    @Override
    public List<AddAllHospital> selectAlllist() {
        return addAllHospitalMapper.findAll();
    }

    @Override
    public List<AddAllHospital> selectByname(String pname) {
        return addAllHospitalMapper.findAllbyname(pname);
    }

    @Override
    @Transactional
    public int insert(AddAllHospital addAllHospital) {
        AdHospital adHospital=new AdHospital();
        Patient patient=new Patient();
        BeanUtils.copyProperties(addAllHospital,adHospital);
        BeanUtils.copyProperties(addAllHospital,patient);
        adHospitalMapper.insert(adHospital);
        patientMapper.insert(patient);
        return 0;
    }

    @Override
    public int update(AdHospital adHospital) {
        adHospitalMapper.update(adHospital);
        return 0;
    }
}
